package com.web.user.member.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.web.user.member.utils.CookieUtils;

import cn.mysteel.util.StringUtils;

public class SendMessageFilter implements Filter
{

	@Override
	public void init(FilterConfig filterConfig) throws ServletException
	{
		
		
	}

	@Override
	public void doFilter(ServletRequest request, ServletResponse response,FilterChain chain) throws IOException, ServletException
	{
		
		HttpServletRequest req= (HttpServletRequest) request;   
		HttpServletResponse resp= (HttpServletResponse) response;  
		
		String memberId = CookieUtils.getCookieValue (req ,"member_id");
		String callback = req.getParameter ("callback");
		String id = req.getParameter ("receiveId");
		
		if(!StringUtils.isTrimEmpty (memberId)&&StringUtils.notNull (id))
		{
			
			req.getRequestDispatcher("/kj/sendMessage.html?receiveId="+id+"&callback="+callback).forward(request, response);
		}else if(StringUtils.isTrimEmpty (memberId)){
		
			resp.sendRedirect ("/login");
		}else if(StringUtils.isNull (id))
		{
			resp.sendRedirect ("/");
		}
		
	}

	@Override
	public void destroy()
	{
		
		
	}
	
}
